package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.mapper.CheckItemMapper;
import com.itheima.pojo.CheckItem;

import com.itheima.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * <h3>health94_pareant</h3>
 * <p></p>
 *
 * @author : hhw
 * @date : 2020-03-17 21:02
 **/


@Service(interfaceClass = CheckItemService.class)
public class CheckItemServiceImpl implements CheckItemService {

    @Autowired
    private CheckItemMapper checkItemMapper;
    @Override
    public void addCheckItem(CheckItem checkItem)throws Exception{

            checkItemMapper.addCheckItem(checkItem);

    }

    @Override
    public PageResult findPage(Integer currentPage, Integer pageSize, String queryString) {

        PageHelper.startPage(currentPage, pageSize);
        List<CheckItem> list = checkItemMapper.findPage(queryString);
        PageInfo<CheckItem> checkItemPageInfo = new PageInfo<>(list);
        return new PageResult(checkItemPageInfo.getTotal(), checkItemPageInfo.getList());

    }

    @Override
    public void deleteByCode(Integer id) {
        int count = checkItemMapper.findCheckItemGroup(id);
        if (count == 0) {
            checkItemMapper.deleteByCode(id);
        } else {
            throw new RuntimeException(MessageConstant.CHECKITEM_IS_QUOTED);
        }
    }

    @Override
    public void update(CheckItem checkItem) {
        checkItemMapper.update(checkItem);
    }

    @Override
    public List<CheckItem> findAllCheckItem() {

        return checkItemMapper.findAllCheckItem();
    }

}
